﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.BusinessObjects;
using yncTech.Common;

public partial class Admin_Sys_Sec_Sec002a : AdminBasePage
{
    decimal? roleId;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString[TSRoleFunctionsMetadata.ColumnNames.RoleID] != null)
        {
            roleId = decimal.Parse(Request.QueryString[TSRoleFunctionsMetadata.ColumnNames.RoleID]);
        }
        if (!IsPostBack)
        {
            switch (ActionType)
            {
                case OperationType.Add:
                    btnSave.Text = "新增";
                    radActive.Checked = true;
                    break;
                case OperationType.Update:
                    if (roleId.HasValue)
                    {
                        TSRole role = new TSRole();
                        if (role.LoadByPrimaryKey(roleId.Value))
                        {
                            txtSysName.Text = role.RoleName;
                            if (role.IsActive.HasValue && role.IsActive.Value)
                            {
                                radActive.Checked = true;
                            }
                            else
                            {
                                rad24.Checked = true;
                            }
                        }
                        btnSave.Text = "修改";
                    }
                    break;
                case OperationType.Delete:
                    btnSave_Click(null, null);
                    break;
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            TSRole role = new TSRole();
            switch (ActionType)
            {
                case OperationType.Add:
                    role.RoleName = txtSysName.Text.Trim();
                    role.IsActive = radActive.Checked;
                    role.CreatedBy = LoginUserInfo.CurrentUser.LoginName;
                    role.LastUpdatedBy = LoginUserInfo.CurrentUser.LoginName;
                    role.Save();
                    break;
                case OperationType.Update:
                    role.LoadByPrimaryKey(roleId.Value);
                    role.RoleName = txtSysName.Text.Trim();
                    role.CreatedBy = LoginUserInfo.CurrentUser.LoginName;
                    role.IsActive = radActive.Checked;
                    role.LastUpdatedBy = LoginUserInfo.CurrentUser.LoginName;
                    role.Save();
                    break;
                case OperationType.Delete:
                    role.LoadByPrimaryKey(roleId.Value);
                    role.MarkAsDeleted();
                    role.Save();
                    WebHelper.GotoParent();
                    break;
            }
            WebHelper.CloseDialog(true);
        }
        catch (Exception ex)
        {
            lbMessage.Text = ex.Message;
        }
    }

    protected void btnClose_Click(object sender, EventArgs e)
    {
        WebHelper.CloseDialog();
    }
}